﻿import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

public class BufferedWriter {
	public static void main(String[] args) {
		//1.创建一个Bufferedwriter

				Writer wr=null;
				BufferedWriter br=null;
				Reader rd=null;
				BufferedReader bw=null;
				try {
					wr=new FileWriter("d://1.txt");
					br=new BufferedWriter(wr);
					//写入信息

					br.write("HELLO，");
					br.newLine();
					br.write("我是你梦成霸霸，");
					br.newLine();
					br.write("请跟我一起装逼");
					br.flush();
					//读取文件中的信息

					rd=new FileReader("d://1.txt");
					bw=new BufferedReader(rd);
					String line;//读取到的信息

					while((line=bw.readLine())!=null){
						System.out.println(line);
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block

					e.printStackTrace();
				}
				finally{
					if(br!=null){
						try {
							br.close();
						} catch (IOException e) {
							// TODO Auto-generated catch block

							e.printStackTrace();
						}
					}
					if(bw!=null){
						try {
							bw.close();
						} catch (IOException e) {
							// TODO Auto-generated catch block

							e.printStackTrace();
						}
					}
					if(wr!=null){
						try {
							wr.close();
						} catch (IOException e) {
							// TODO Auto-generated catch block

							e.printStackTrace();
						}
					}
					if(rd!=null){
						try {
							rd.close();
						} catch (IOException e) {
							// TODO Auto-generated catch block

							e.printStackTrace();
						}
					}
				}
	}
}